function ShowImg(IMG,IMG_X,IMG_Y)
{
	var URL = "";
	var NAME = "";
	var OPTION = "left=0,top=0,width="+IMG_X+",height="+IMG_Y+",resizable=no,scrollbars=no";

	var HTML = "<img src='"+IMG+"' style='cursor:pointer' onclick='self.close();'>";

	var OpenImg = window.open(URL,NAME,OPTION);
	OpenImg.document.title = "확대이미지";
	OpenImg.document.body.style.margin = "0px";
	OpenImg.document.body.innerHTML = HTML;
}

function Cart(MOD,GCODE,CNT,GOPTION)
{
	new ajax("cart_update.php?MOD="+MOD+"&GCODE="+GCODE+"&CNT="+CNT+"&GOPTION="+GOPTION,CartResult);
}

function CartResult(Result)
{
	var DATA=Result.responseText;
	if(DATA == "TRUE")
	{
		location.href='./cart.php';
	}
	else
	{
		alert(DATA);
	}
}

function DirectBuy(MOD,GCODE,CNT,GOPTION)
{
	new ajax("cart_update.php?MOD="+MOD+"&GCODE="+GCODE+"&CNT="+CNT+"&GOPTION="+GOPTION,DirectBuyResult);
}

function DirectBuyResult(Result)
{
	var DATA=Result.responseText;
	if(DATA == "TRUE")
	{
		location.href='order_step1.php';
	}
	else
	{
		alert(DATA);
	}
}


function copyBuyer()
{
	if(document.all('os_same').checked == true)
	{
		var frm = document.order_step1;

		frm.s_name.value = frm.o_name.value;
		frm.s_tel.value = frm.o_tel.value;
		frm.s_hp.value = frm.o_hp.value;
		frm.s_email.value = frm.o_email.value;
		frm.s_zip1.value = frm.o_zip1.value;
		frm.s_zip2.value = frm.o_zip2.value;
		frm.s_addr1.value = frm.o_addr1.value;
		frm.s_addr2.value = frm.o_addr2.value;
	}
}

function order_step2()
{
	var frm = document.order_step1;

	if(frm.o_name.value == "")
	{
		alert("주문자명을 입력하세요.");
		frm.o_name.focus();
	}
	else if(frm.o_tel.value == "" && frm.o_hp.value == "")
	{
		alert("주문자 연락처를 입력하세요.");
		frm.o_tel.focus();
	}
	else if(frm.o_email.value == "")
	{
		alert("주문자 E-mail을 입력하세요.");
		frm.o_email.focus();
	}
	else if(frm.o_zip1.value == "" || frm.o_zip2.value == "" || frm.o_addr1.value == "" || frm.o_addr2.value == "")
	{
		alert("주문자 주소를 입력하세요.");
		document.all('o_zip_btn').focus();
	}
	else if(frm.s_name.value == "")
	{
		alert("수령자명을 입력하세요.");
		frm.s_name.focus();
	}
	else if(frm.s_tel.value == "" && frm.s_hp.value == "")
	{
		alert("수령자 연락처를 입력하세요.");
		frm.s_tel.focus();
	}
	else if(frm.s_email.value == "")
	{
		alert("수령자 E-mail을 입력하세요.");
		frm.s_email.focus();
	}
	else if(frm.s_zip1.value == "" || frm.s_zip2.value == "" || frm.s_addr1.value == "" || frm.s_addr2.value == "")
	{
		alert("수령자 주소를 입력하세요.");
		document.all('s_zip_btn').focus();
	}
	else
	{
		if(confirm('다음단계로 진행하시겠습니까?'))
		{
			frm.submit();
		}
		else
		{
			return false;
		}
	}
}

function PayMethodShow(Obj)
{
	document.all('normal').style.display = 'none';
	document.all('iche').style.display = 'none';
	document.all('bank').style.display = 'none';
	document.all(Obj).style.display = 'inline';
}



function number_format(data)
{
	var newValue = data+"";
	var len = newValue.length;  
	var ch="";
	var j=1;
	var formatValue="";
  
	newValue = newValue.replace(/\,/gi, ' ');
  
	len = newValue.length;

	for(i=len ; i>0 ; i--)
	{
		ch = newValue.substring(i-1,i);
		formatValue = ch + formatValue;
		if ((j%3) == 0 && i>1 )
		{
			formatValue=","+formatValue;
		}
		j++;
	}
	return formatValue;
}
 

function no_comma(data)
{
	return (data+"").replace(/\,/gi, '');
}

function Numeric(data) 
{ 
	if (data.length > 0) 
	{ 
		var continu = true;
		for (i = 0; i < data.length; i++) 
		{ 
			if (data.charAt(i) < '0' || data.charAt(i) > '9') 
			{ 
				continu = false;
			}
		}

		return continu;
	}
	else
	{
		return false;
	}
}

function PointUse()
{
	var frm = document.order_step2;
	var myPoint =  no_comma(frm.my_point.value);//보유포인트
	var usePoint = no_comma(frm.use_point.value);//사용포인트
	var payPrice = no_comma(frm.pay_price.value);
	var payTranc = no_comma(frm.pay_tranc.value)


	if(usePoint.length > 1 && usePoint.charAt(0)=="0")
	{
		usePoint = usePoint.substr(1,usePoint.length-1);
	}

	if(Numeric(usePoint))
	{
		if(myPoint >= usePoint)
		{
			if((eval(payPrice) + eval(payTranc)) >= usePoint)
			{
				if(usePoint % 100)
				{
					alert("포인트 결제는 100점 단위로 가능합니다.");
					frm.use_point.value = "0";
					frm.end_point.value = number_format(myPoint);
					frm.pay_point.value = "0";
					frm.pay_amount.value = number_format(eval(payPrice) + eval(payTranc));
				}
				else
				{
					frm.use_point.value = number_format(usePoint);
					frm.end_point.value = number_format(eval(myPoint) - eval(usePoint));
					frm.pay_point.value = number_format(usePoint);
					frm.pay_amount.value = number_format(eval(payPrice) + eval(payTranc)  - eval(usePoint));
				}
			}
			else
			{
				alert("결제금액을 초과할 수 없습니다.");
				frm.use_point.value = "0";
				frm.end_point.value = number_format(myPoint);
				frm.pay_point.value = "0";
				frm.pay_amount.value = number_format(eval(payPrice) + eval(payTranc));
			}
		}
		else
		{
			alert("사용할 수 있는 포인트를 초과하였습니다.");
			frm.use_point.value = "0";
			frm.end_point.value = number_format(myPoint);
			frm.pay_point.value = "0";
			frm.pay_amount.value = number_format(eval(payPrice) + eval(payTranc));
		}
	}
}


function order_step3()
{
	var frm = document.order_step2;

	var payMethod = frm.pay_method.length;
	var chkPayMethod = false;
	var payMethodValue = "";
	for(i=0;i<payMethod;i++)
	{
		if(frm.pay_method[i].checked == true)
		{
			chkPayMethod = true;
			payMethodValue = frm.pay_method[i].value;
		}
	}

	if(!chkPayMethod)
	{
		alert("결제방법을 선택하세요.");
		frm.pay_method[0].focus();
	}
	else if((payMethodValue == "card" || payMethodValue == "hp" || payMethodValue == "ebank") && frm.pay_user.value == "")
	{
		alert("결제자명을 입력하세요.");
		frm.pay_user.focus();
	}
	else if(payMethodValue == "iche" && frm.pay_iche_user.value == "")
	{
		alert("결제자명을 입력하세요.");
		frm.pay_iche_user.focus();
	}
	else if(payMethodValue == "iche" && (frm.pay_pid1.value == "" || frm.pay_pid2.value == ""))
	{
		alert("결제자 주민번호를 입력하세요.");
		frm.pay_pid1.focus();
	}
	else if(payMethodValue == "bank" && frm.bank_info.value == "")
	{
		alert("입금계좌를 선택하세요.");
		frm.bank_info.focus();
	}
	else if(payMethodValue == "bank" && frm.bank_user.value == "")
	{
		alert("입금자명을 입력하세요.");
		frm.bank_user.focus();
	}
	else
	{
		if(confirm("다음단계로 진행하시겠습니까?"))
		{
			frm.submit();
		}
		else
		{
			return false;
		}
	}
}

function order_step4()
{
	var frm = document.payForm;

	if(frm.pay_method.value == "bank")
	{
		if(confirm("결제 하시겠습니까?"))
		{
			location.href='order_step3_bank.php';
		}
		else
		{
			return false;
		}

	}
	else
	{
		if(frm.shop_mode.value == "TEST")
		{
			if(frm.pay_method.value == "card")
			{
				frm.action = "http://pg.dacom.net:7080/card/cardAuthAppInfo.jsp";
			}
			else if(frm.pay_method.value == "iche")
			{
				frm.action = "http://pg.dacom.net:7080/transfer/transferSelectBank.jsp";
			}
			else if(frm.pay_method.value == "hp")
			{
				frm.action = "http://pg.dacom.net:7080/wireless/wirelessAuthAppInfo1.jsp";
			}
			else if(frm.pay_method.value == "ebank")
			{
				frm.action = "http://pg.dacom.net:7080/cas/casRequestSA.jsp";
			}
			else
			{
				return false;
			}

			if(frm.action != "")
			{
				if(confirm("결제 하시겠습니까?"))
				{
					document.all('PG_BG_LAYER').style.display = "inline";
					document.all('PG_LAYER').style.display = "inline";
					frm.submit();
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
		else
		{
			if(frm.pay_method.value == "card")
			{
				frm.action = "http://pg.dacom.net/card/cardAuthAppInfo.jsp";
			}
			else if(frm.pay_method.value == "iche")
			{
				frm.action = "http://pg.dacom.net/transfer/transferSelectBank.jsp";
			}
			else if(frm.pay_method.value == "hp")
			{
				frm.action = "http://pg.dacom.net/wireless/wirelessAuthAppInfo1.jsp";
			}
			else if(frm.pay_method.value == "ebank")
			{
				frm.action = "http://pg.dacom.net/cas/casRequestSA.jsp";
			}
			else
			{
				return false;
			}

			if(frm.action != "")
			{
				if(confirm("결제 하시겠습니까?"))
				{
					document.all('PG_BG_LAYER').style.display = "inline";
					document.all('PG_LAYER').style.display = "inline";
					frm.submit();
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
	}
}

function PG_CLOSE()
{
	if(confirm("결제창을 닫으시겠습니까?"))
	{
		document.all('PG_LAYER').style.display = "none";
		document.all('PG_BG_LAYER').style.display = "none";
	}
	else
	{
		return false;
	}
}